package com.laisheng.interview.service.impl;

import com.laisheng.interview.mapper.DevelopmentExercisesMapper;
import com.laisheng.interview.model.DevelopmentExercises;
import com.laisheng.interview.model.ResponseDTO;
import com.laisheng.interview.service.ExerciseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 开发练习题服务实现类
 */
@Service
public class ExerciseServiceImpl implements ExerciseService {
    @Autowired
    private DevelopmentExercisesMapper developmentExercisesMapper;

    /**
     * 获取所有练习题
     * @return 练习题列表
     */
    public List<DevelopmentExercises> getAllExercises() {
        return developmentExercisesMapper.getAll();
    }
    
    /**
     * 根据面试者ID获取练习题
     * @param accountingId 面试者ID
     * @return 练习题列表
     */
    public List<DevelopmentExercises> getExercisesByAccountingId(Long accountingId) {
        return developmentExercisesMapper.getByAccountingId(accountingId);
    }
    public ResponseDTO save(DevelopmentExercises exercises){
        try {
            int rows = developmentExercisesMapper.saveExercise(exercises);
            return rows > 0 ? ResponseDTO.success("提交成功") : ResponseDTO.error("提交失败");
        } catch (Exception e) {
            return ResponseDTO.error("服务器错误：" + e.getMessage());
        }
    }
}
